<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	        <tr>
	        	<td style="width: 100%;">
	        			订单编号：
	                <input id="ser_no" class="mini-textbox" emptyText="请输入订单编号" style="width:150px;" />  
	                	客户姓名： 
	                <input id="cus_name" class="mini-textbox" emptyText="请输入姓名" style="width:150px;" />   
	        	</td>
	            <td style="white-space:nowrap;" >
	                <a class="mini-button" onclick="search()" >查询</a>
	            </td>
	        </tr>
	    </table>           
	</div>
	<div id="toolbar1" class="mini-toolbar" style="padding:2px;">
	    <table style="width:100%;">
	        <tr>
		        <td style="width:100%;">
		        	<sec:authorize url='/allocation_init_export_current4.do'>
		        	<a class="mini-button" iconCls="icon-download" onclick="exportCurrent()">导出当前</a>
		        	</sec:authorize>
		        	<sec:authorize url='/allocation_init_export_current4.do'>
                    <a class="mini-button" iconCls="icon-download" onclick="exportAll()">导出全部</a>
                    </sec:authorize>
                    <sec:authorize url='/allocation_center_recover.do'>
		            <a class="mini-button" iconCls="icon-redo" onclick="recover" plain="true">回收订单</a>
		            </sec:authorize>
		        </td>
	        </tr>
	    </table>
	</div>
	<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20" onlyCheckSelection="true" url="allocation_center_view.do" style="width:100%;height:100%;" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn"></div>
			<div type="checkcolumn"></div>
			<div name="action" width="70" headerAlign="center" align="center" renderer="onActionRenderer">相关操作</div>
			<div field="serialNum" width="100" headerAlign="center" align="center">订单编号</div>
			<div field="createTime" width="115" headerAlign="center" align="center" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss">下单时间</div>
			<div field="name" width="55" headerAlign="center" align="center">收货人</div>
			<div field="address" width="160" headerAlign="center" align="center">收货地址</div>
			<div field="payment" width="60" headerAlign="center" align="center">货款金额</div>
			<div field="freight" width="60" headerAlign="center" align="center">运费</div>
			<div field="totalMoney" width="70" headerAlign="center" align="center">总金额</div>
			<div field="groupName" width="120" headerAlign="center" align="center">核单组</div>
			<div field="checkUserName" width="55" headerAlign="center" align="center">核单员</div>
		</div>
	</div>
	</div>

<script type="text/javascript">
	mini.parse();
	
	var grid = mini.get("datagrid1");
	grid.load({listType: 1});

	//导出当前
	function exportCurrent(){
	 	var data = grid.data;
        var ids = [];
        $.each(data , function(){
            ids.push(this.id);
        });
        var id = ids.join(',');
        location.href="allocated_init_export_current.do?ids=" +id;
        grid.reload();
	}
	
	//导出所有
	function exportAll(){
		var serNo = mini.get("ser_no").getValue();
		var cusName = mini.get("cus_name").getValue();
		location.href="allocated_center_export_all.do?serialNum="+serNo+"&name="+cusName+"&allocateGrade="+"1";
	}
	
	//相关操作
 	function onActionRenderer(e) {
 		var record = e.record;
    	return '<a style="width:150px;" href="javascript: ordersView('+record._uid+')">打开订单</a>';
    }
	
 	function ordersView(row_uid) {
    	var row = grid.getRowByUID(row_uid);
    	mini.open({
            url: "orders_find_open_init.do?id=" + row.id,
            title: "打开订单", width: 850, height: 650,
            allowResize: false
        });
    }
 	
 	// 获取批量选择的数据
	function getSelectRows(){
		var rows = grid.getSelecteds();
		var id = [];
		if(rows.length > 0){
			var ids = [];
            for (var i = 0, l = rows.length; i < l; i++) {
                var r = rows[i];
                ids.push(r.id);
            }
            id = ids.join(',');
		}
		return id;
	}
	
	// 回收
	function recover() {
		var ordersIds = getSelectRows();
		if(ordersIds.length > 0) {
			$.post("allocation_center_recover.do", {id: ordersIds}, function(data) {
				if(data.success) {
					mini.showMessageBox({
		                title: "提示",
		                showModal:false,
		                iconCls: "mini-messagebox-info",
		                message: "回收成功！",
		                timeout: 3000,
		                x: 'right',
		                y: 'bottom',
		            });
					grid.reload();
				}else {
					mini.alert("回收失败，请刷新列表后重试！");
				}
			}, "json");
		}else {
			mini.alert("未选择任何数据！");
		}
	}
	
	function viewDetail() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "audit_orders_detail_init.do",
                title: "查看订单", width: 900, height: 600,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { row: row };
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        } else {
            alert("请选中一条记录");
        }
    }
    
    function search() {
    	var serNo = mini.get("ser_no").getValue();
		var cusName = mini.get("cus_name").getValue();
		grid.load({ listType: 1, serialNum: serNo, name: cusName });
    }
    
</script>
</body>
</html>